/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sadhar.sipp.pospendapatan;

import org.sadhar.sia.framework.ClassApplicationModule;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 *
 * @author hendro
 */
public class PosPendapatanPopupWnd extends ClassApplicationModule{
    private Listbox lstboxPosPendapatan;
    private Textbox txtboxKeySearch;
    private PosPendapatanDAO posDAO;

    public PosPendapatanPopupWnd(){        
        posDAO = new PosPendapatanDAOImpl();
    }

    public void onCreate()throws Exception{
        lstboxPosPendapatan = (Listbox)getFellow("lstboxPosPendapatan");
        txtboxKeySearch = (Textbox)getFellow("txtboxKeySearch");
        loadPosPendapatan();
    }

    private void loadPosPendapatan()throws Exception{
        lstboxPosPendapatan.getItems().clear();
        for(PosPendapatan pos : posDAO.listAll(txtboxKeySearch.getValue())){
            Listitem item = new Listitem();
            item.setValue(pos);
            item.appendChild(new Listcell(pos.getNamaPosPendapatan()));
            lstboxPosPendapatan.appendChild(item);
        }
    }

    public void lstboxPosPendapatanOnSelect()throws Exception{
        PosPendapatan pos = (PosPendapatan)lstboxPosPendapatan.getSelectedItem().getValue();
        Window window = (Window) this.getRoot().getFellow("contentDiv").getFirstChild();
        Textbox txtboxIdPosPendapatan = (Textbox)window.getFellow("txtboxIdPosPendapatan");
        Textbox txtboxPosPendapatan = (Textbox)window.getFellow("txtboxPosPendapatan");
        txtboxPosPendapatan.setValue(pos.getNamaPosPendapatan());
        txtboxIdPosPendapatan.setValue(String.valueOf(pos.getIdPosPendapatan()));
        this.detach();
    }
}
